package cn.edu.ujn.lab3.service;

import java.util.List;

import cn.edu.ujn.lab3.utils.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.ujn.lab3.dao.BaseDict;
import cn.edu.ujn.lab3.dao.BaseDictMapper;
/**
 * 数据字典Service接口实现类
 */
@Service("baseDictService")
public class BaseDictServiceImpl implements BaseDictService {

	@Autowired
	private BaseDictMapper baseDictDao;

	
	@Override
	//根据类别代码查询数据字典
	public List<BaseDict> findBaseDictByTypeCode(String typecode) {
		// TODO Auto-generated method stub
		return baseDictDao.selectBaseDictByTypeCode(typecode);
	}

    @Override
    public Page<BaseDict> findBaseDictList(Integer page, Integer rows, String dictTypeCode, String dictTypeName, String dictItemName) {
        BaseDict baseDict = new BaseDict();
        baseDict.setDict_type_code(dictTypeCode);
        baseDict.setDict_type_name(dictTypeName);
        baseDict.setDict_item_name(dictItemName);
        // 当前页
        baseDict.setStart((page-1) * rows) ;
        // 每页数
        baseDict.setRows(rows);
        // 查询客户列表
        List<BaseDict> goodsList =
                baseDictDao.selectBaseDictList(baseDict);
        // 查询客户列表总记录数
        Integer count = baseDictDao.selectBaseDictListCount(baseDict);
        // 创建Page返回对象
        Page<BaseDict> result = new Page<>();
        result.setPage(page);
        result.setRows(goodsList);
        result.setSize(rows);
        result.setTotal(count);
        return result;
    }

    @Override
    public List<BaseDict> selectList(BaseDict baseDict) {
        return  baseDictDao.selectBaseDictList(baseDict);
    }

    @Override
    public int createBaseDicts(BaseDict baseDict) {
        return baseDictDao.insert(baseDict);
    }

    @Override
    public int updateBaseDict(BaseDict baseDict) {
        return baseDictDao.updateByPrimaryKey(baseDict);
    }

    @Override
    public int deleteBaseDict(String id) {
        return baseDictDao.deleteByPrimaryKey(id);
    }

    @Override
    public BaseDict getBaseDictById(String id) {
        return baseDictDao.selectByPrimaryKey(id);
    }

}
